package com.lb.jwitter.action;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import org.springframework.test.context.ContextConfiguration;
import com.lb.jwitter.util.ApplicationContextProvider; 
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.ConditionReport; 
import java.util.Map; 
 import com.opensymphony.xwork2.ActionContext; 
import com.lb.jwitter.util.Message; 
import com.lb.jwitter.service.TblQLDTTXAHoSoDiemXetTuyen;
import com.lb.jwitter.service.TblQLDTTXAHoSoDiemXetTuyenService;
import com.lb.jwitter.service.TblQuyenChiTietService;import com.lb.jwitter.service.TblTaiKhoan;import com.lb.jwitter.service.TblQLDTTXAHoSoXetTuyen;
import com.lb.jwitter.service.TblQLDTTXAHoSoXetTuyenService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXAHoSoXetTuyenDeleteAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private String dataString; 
    public String getDataString() { return dataString; }

    private Message msg; 
    public Message getMsg() { return msg; }

    private String idList; 
    public String getIdList() { return idList; } 
    public void setIdList(String idList) { this.idList = idList; }

    private Collection<TblQLDTTXAHoSoXetTuyen> tblQLDTTXAHoSoXetTuyens; 
    public Collection<TblQLDTTXAHoSoXetTuyen>  getTblQLDTTXAHoSoXetTuyens() {
         return tblQLDTTXAHoSoXetTuyens; 
      } 

    private TblQLDTTXAHoSoXetTuyenService tblQLDTTXAHoSoXetTuyenService; 
    private TblQLDTTXAHoSoDiemXetTuyenService tblQLDTTXAHoSoDiemXetTuyenService;

	private int preDelete(Message msg, String ids ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postDelete(Message msg, String ids ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
 public String execute() throws Exception 
{ 
 try{ 	
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HoSoXetTuyen", "xoa")){ 
        return "noprivilege"; 
    } 
tblQLDTTXAHoSoXetTuyenService = (TblQLDTTXAHoSoXetTuyenService) context.getBean("tbl_QLDTTXA_HoSoXetTuyenClient");
tblQLDTTXAHoSoDiemXetTuyenService = (TblQLDTTXAHoSoDiemXetTuyenService) context.getBean("tbl_QLDTTXA_HoSo_DiemXetTuyenClient");
     msg = new Message(); 

    List<String> ids = new ArrayList<String>(); 
    Collections.addAll(ids, idList.split(",")); 
    //tblQLDTTXAHoSoXetTuyenService.deleteListtblQLDTTXAHoSoXetTuyen(ids); 
    for(String id : ids){
    	TblQLDTTXAHoSoXetTuyen hoSo = tblQLDTTXAHoSoXetTuyenService.gettblQLDTTXAHoSoXetTuyen(new Long(id));
    	if(hoSo.getTrangThaiId() == 1){
    		List<ConditionReport> cons = new ArrayList<ConditionReport>();
    		{ 
		       ConditionReport con = new ConditionReport(); 
		       con.setCol("hoSoId.id"); 
		       con.setValue1(hoSo.getId()); 
		       con.setOperator("eq"); 
		       cons.add(con); 
		   }
    		List<TblQLDTTXAHoSoDiemXetTuyen> diemXetTuyens = tblQLDTTXAHoSoDiemXetTuyenService.findtblQLDTTXAHoSoDiemXetTuyenByCondition(cons, 0, 0);
    		for(TblQLDTTXAHoSoDiemXetTuyen diemXetTuyen : diemXetTuyens){
    			tblQLDTTXAHoSoDiemXetTuyenService.deletetblQLDTTXAHoSoDiemXetTuyen(diemXetTuyen.getId());
    		}
    		tblQLDTTXAHoSoXetTuyenService.deletetblQLDTTXAHoSoXetTuyen(hoSo.getId());
    	}
    }
       if(pageSize == 0){ 
           pageSize = 20; 
       } 
        if(page == 0){ 
           page =1; 
       } 
      tblQLDTTXAHoSoXetTuyens =       tblQLDTTXAHoSoXetTuyenService.findAlltblQLDTTXAHoSoXetTuyen(pageSize, page); 
      pages = tblQLDTTXAHoSoXetTuyenService.counttblQLDTTXAHoSoXetTuyenByCondition(new ArrayList<ConditionReport>())/pageSize + 1; 
      dataString = ""; 
      dataString += "&id="; 
      dataString += "&email="; 
      dataString += "&diaChi="; 
      dataString += "&dienThoai="; 
      dataString += "&hoTen="; 
      dataString += "&hinhAnh="; 
      dataString += "&maHoSo="; 
      dataString += "&ngaySinh="; 
      dataString += "&noiSinh="; 
      dataString += "&gioiTinh="; 
      dataString += "&thongBaoId="; 
      dataString += "&chiNhanhId="; 
      dataString += "&trangThaiId="; 
      dataString += "&khoaId="; 
      dataString += "&nganhId="; 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
      System.out.println("Loi Delete tbl_QLDTTXA_HoSoXetTuyen Action"); 
     e.printStackTrace(); 
    return Action.ERROR; 
 } 
 } 
 } 
 
